from django.utils.deprecation import MiddlewareMixin
from django.shortcuts import HttpResponse
import time

vst_record = {}
class MD1(MiddlewareMixin):
    def process_request(self, request):
        ip = request.META.get("REMOTE_ADDR")
        now = time.time()
        if ip not in vst_record:
            vst_record[ip] = []
        record = vst_record[ip]
        while record and now - record[-1] > 5:
            record.pop()
        if len(record) >= 3:
            return HttpResponse("等一哈")
        record.insert(0, now)
